package Application;

import Extended.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.filechooser.*;


class MainWindow extends GeneralMessage
{
	public final String ClassName = this.getClass().getName();

	public JFrame FrameWindow;

	public int ControlKey;

	public String CurrentProgress;
	public boolean ProgressModifyied;
	public boolean ProgressRevertModifyied;
	public String OldProgressText;
	public Dimension OldWindowSize;
	public boolean MessageBoxShow;

	public int TangramLength;
	public boolean ShowHiddenTangram;
	public ShapeValue SelectedTangram;
	public String SelectedShape;
	public String SelectedVar;
	public int SelectedArray;

	public final int TangramMaximum = 8;
	public final int TangramSpace = 4;
	public final int ZoomMax = 400;
	public final int ZoomSize = 50;
	public final int WindowWidth = 485;
	public final int WindowHeight = 505;
	public final int WindowX = (screensize.width / 2) - (WindowWidth / 2);
	public final int WindowY = (screensize.height / 2) - (WindowHeight / 2);

	public final Color t1DefaultColor = new Color(201, 232, 145);
	public final Color t2DefaultColor = new Color(104, 192, 210);
	public final Color t3DefaultColor = new Color(240, 242, 35);
	public final Color t4DefaultColor = new Color(241, 149, 200);
	public final Color t5DefaultColor = new Color(248, 200, 44);
	public final Color s1DefaultColor = new Color(167, 150, 194);
	public final Color d1DefaultColor = new Color(239, 61, 97);

	public ShapeValue t1[] = new ShapeValue[TangramMaximum];
	public ShapeValue t2[] = new ShapeValue[TangramMaximum];
	public ShapeValue t3[] = new ShapeValue[TangramMaximum];
	public ShapeValue t4[] = new ShapeValue[TangramMaximum];
	public ShapeValue t5[] = new ShapeValue[TangramMaximum];
	public ShapeValue d1[] = new ShapeValue[TangramMaximum];
	public ShapeValue s1[] = new ShapeValue[TangramMaximum];

	public JMenuItem MenuItemNew;
	public JMenuItem MenuItemOpen;
	public JMenuItem MenuItemClose;
	public JMenuItem MenuItemSave;
	public JMenuItem MenuItemSaveAs;
	public JMenuItem MenuItemRevert;
	public JMenuItem MenuItemCopyScreenShot;
	public JMenuItem MenuItemAddTangram;
	public JMenuItem MenuItemRemoveTangram;
	public JMenuItem MenuItemQuit;
	public JMenuItem MenuItemZoomIn;
	public JMenuItem MenuItemZoomOut;
	public JMenuItem MenuItemRotateLeft;
	public JMenuItem MenuItemRotateRight;
	public JMenuItem MenuItemVerticalInvert;
	public JMenuItem MenuItemHorizontalInvert;
	public JMenuItem MenuItemChangeColor;
	public JCheckBoxMenuItem MenuItemHide;
	public JCheckBoxMenuItem MenuItemShowHiddenTangram;
	public JMenuItem MenuItemMinimize;
	public JMenuItem MenuItemMaximize;
	public JMenuItem MenuItemAbout;
	public JMenuItem MenuItemHelp;

	public JMenu MenuGame;
	public JMenu MenuControl;
	public JMenu MenuView;
	public JMenu MenuWindow;
	public JMenu MenuHelp;

	public JMenuBar MenuBar;

	public FileDialog FileChooser;
	public JColorChooser ColorChooser;

	public MainWindow()
	{
		try
		{
			FrameWindow = new JFrame()
			{
				public void paint(Graphics g)
				{
					try
					{
						int i;
						Graphics2D g2d = (Graphics2D) g;
						GeneralPath gp;

						g2d.setStroke(new BasicStroke(2.0f));

						super.paint(g);

						for(i = 0; i < TangramLength; i ++)
						{
							if(t1[i].visible || ShowHiddenTangram)
							{
								gp = GetShape.GetTriangle(t1[i].x, t1[i].y, t1[i].size, t1[i].rotate);

								g.setColor(t1[i].color);

								g2d.fill(gp);
							}

							if(t2[i].visible || ShowHiddenTangram)
							{
								gp = GetShape.GetTriangle(t2[i].x, t2[i].y, t2[i].size, t2[i].rotate);

								g.setColor(t2[i].color);

								g2d.fill(gp);
							}

							if(t3[i].visible || ShowHiddenTangram)
							{
								gp = GetShape.GetTriangle(t3[i].x, t3[i].y, t3[i].size, t3[i].rotate);

								g.setColor(t3[i].color);

								g2d.fill(gp);
							}

							if(t4[i].visible || ShowHiddenTangram)
							{
								gp = GetShape.GetTriangle(t4[i].x, t4[i].y, t4[i].size, t4[i].rotate);

								g.setColor(t4[i].color);

								g2d.fill(gp);
							}

							if(t5[i].visible || ShowHiddenTangram)
							{
								gp = GetShape.GetTriangle(t5[i].x, t5[i].y, t5[i].size, t5[i].rotate);

								g.setColor(t5[i].color);

								g2d.fill(gp);
							}

							if(s1[i].visible || ShowHiddenTangram)
							{
								gp = GetShape.GetSquare(s1[i].x, s1[i].y, s1[i].size, s1[i].rotate);

								g.setColor(s1[i].color);

								g2d.fill(gp);
							}

							if(d1[i].visible || ShowHiddenTangram)
							{
								gp = GetShape.GetDiamond(d1[i].x, d1[i].y, d1[i].size, d1[i].rotate);

								g.setColor(d1[i].color);

								g2d.fill(gp);
							}
						}

						if(SelectedTangram != null)
						{
							switch(SelectedShape)
							{
								case "Triangle":
									gp = GetShape.GetTriangle(SelectedTangram.x, SelectedTangram.y, SelectedTangram.size, SelectedTangram.rotate);
									break;
								case "Square":
									gp = GetShape.GetSquare(SelectedTangram.x, SelectedTangram.y, SelectedTangram.size, SelectedTangram.rotate);
									break;
								case "Diamond":
									gp = GetShape.GetDiamond(SelectedTangram.x, SelectedTangram.y, SelectedTangram.size, SelectedTangram.rotate);
									break;
								default:
									gp = null;
							}

							g.setColor(SelectedTangram.color);

							g2d.fill(gp);

							g.setColor(Color.BLACK);

							g2d.draw(gp);
						}

						Refresh();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			};

			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

			if(osname.startsWith("Mac OS"))
				System.setProperty("apple.laf.useScreenMenuBar", "true");

			FrameWindow.setMinimumSize(new Dimension(300, 300));
			FrameWindow.setBounds(WindowX, WindowY, WindowWidth, WindowHeight);
			FrameWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

			ControlKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

			CancelSelected();

			CurrentProgress = null;
			OldWindowSize = FrameWindow.getSize();
			MessageBoxShow = false;

			TangramLength = 0;
			ShowHiddenTangram = false;

			MenuItemNew = new JMenuItem();
			MenuItemNew.setText(GetString("MenuItemNew"));
			MenuItemNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ControlKey));
			MenuItemNew.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						NewProgress();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemOpen = new JMenuItem();
			MenuItemOpen.setText(GetString("MenuItemOpen"));
			MenuItemOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ControlKey));
			MenuItemOpen.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						OpenProgress();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemClose = new JMenuItem();
			MenuItemClose.setText(GetString("MenuItemClose"));
			MenuItemClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ControlKey));
			MenuItemClose.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						CloseProgress();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemSave = new JMenuItem();
			MenuItemSave.setText(GetString("MenuItemSave"));
			MenuItemSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ControlKey));
			MenuItemSave.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						SaveProgress();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemSaveAs = new JMenuItem();
			MenuItemSaveAs.setText(GetString("MenuItemSaveAs"));
			if(osname.startsWith("Mac OS"))
				MenuItemSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ControlKey | KeyEvent.SHIFT_MASK | KeyEvent.ALT_MASK));
			else
				MenuItemSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ControlKey | KeyEvent.SHIFT_MASK));
			MenuItemSaveAs.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						SaveAsProgress();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemRevert = new JMenuItem();
			MenuItemRevert.setText(GetString("MenuItemRevert"));
			MenuItemRevert.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						RevertProgress();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemCopyScreenShot = new JMenuItem();
			MenuItemCopyScreenShot.setText(GetString("MenuItemCopyScreenShot"));
			MenuItemCopyScreenShot.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ControlKey));
			MenuItemCopyScreenShot.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						CopyScreenShot();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemAddTangram = new JMenuItem();
			MenuItemAddTangram.setText(GetString("MenuItemAddTangram"));
			MenuItemAddTangram.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, ControlKey));
			MenuItemAddTangram.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						AddTangram();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemRemoveTangram = new JMenuItem();
			MenuItemRemoveTangram.setText(GetString("MenuItemRemoveTangram"));
			MenuItemRemoveTangram.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, ControlKey));
			MenuItemRemoveTangram.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						RemoveTangram();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemQuit = new JMenuItem();
			MenuItemQuit.setText(GetString("MenuItemQuit"));
			MenuItemQuit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ControlKey));
			MenuItemQuit.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						QuitGame();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemZoomIn = new JMenuItem();
			MenuItemZoomIn.setText(GetString("MenuItemZoomIn"));
			MenuItemZoomIn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, ControlKey));
			MenuItemZoomIn.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						ZoomIn();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemZoomOut = new JMenuItem();
			MenuItemZoomOut.setText(GetString("MenuItemZoomOut"));
			MenuItemZoomOut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, ControlKey));
			MenuItemZoomOut.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						ZoomOut();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemRotateLeft = new JMenuItem();
			MenuItemRotateLeft.setText(GetString("MenuItemRotateLeft"));
			MenuItemRotateLeft.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ControlKey));
			MenuItemRotateLeft.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						RotateLeft();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemRotateRight = new JMenuItem();
			MenuItemRotateRight.setText(GetString("MenuItemRotateRight"));
			MenuItemRotateRight.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, ControlKey));
			MenuItemRotateRight.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						RotateRight();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemVerticalInvert = new JMenuItem();
			MenuItemVerticalInvert.setText(GetString("MenuItemVerticalInvert"));
			if(osname.startsWith("Mac OS"))
				MenuItemVerticalInvert.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ControlKey | KeyEvent.ALT_MASK));
			else
				MenuItemVerticalInvert.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, ControlKey));
			MenuItemVerticalInvert.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						VerticalInvert();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemHorizontalInvert = new JMenuItem();
			MenuItemHorizontalInvert.setText(GetString("MenuItemHorizontalInvert"));
			if(osname.startsWith("Mac OS"))
				MenuItemHorizontalInvert.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, ControlKey | KeyEvent.ALT_MASK));
			else
				MenuItemHorizontalInvert.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_END, ControlKey));
			MenuItemHorizontalInvert.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						HorizontalInvert();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemChangeColor = new JMenuItem();
			MenuItemChangeColor.setText(GetString("MenuItemChangeColor"));
			MenuItemChangeColor.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, ControlKey));
			MenuItemChangeColor.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						ChangeColor();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemHide = new JCheckBoxMenuItem();
			MenuItemHide.setText(GetString("MenuItemHide"));
			MenuItemHide.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_QUOTE, ControlKey));
			MenuItemHide.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						Hide();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemShowHiddenTangram = new JCheckBoxMenuItem();
			MenuItemShowHiddenTangram.setText(GetString("MenuItemShowHiddenTangram"));
			MenuItemShowHiddenTangram.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, ControlKey | KeyEvent.SHIFT_MASK));
			MenuItemShowHiddenTangram.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						ShowHiddenTangram();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemMinimize = new JMenuItem();
			MenuItemMinimize.setText(GetString("MenuItemMinimize"));
			MenuItemMinimize.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ControlKey));
			MenuItemMinimize.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						FrameWindow.setExtendedState(JFrame.ICONIFIED);
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemMaximize = new JMenuItem();
			MenuItemMaximize.setText(GetString("MenuItemMaximize"));
			MenuItemMaximize.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						switch(FrameWindow.getExtendedState())
						{
							case JFrame.NORMAL:
								FrameWindow.setExtendedState(JFrame.MAXIMIZED_BOTH);
								break;
							case JFrame.MAXIMIZED_BOTH:
								FrameWindow.setExtendedState(JFrame.NORMAL);
								break;
						}
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemAbout = new JMenuItem();
			MenuItemAbout.setText(GetString("MenuItemAbout"));
			MenuItemAbout.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						ShowAbout();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuItemHelp = new JMenuItem();
			MenuItemHelp.setText(GetString("MenuItemHelp"));
			MenuItemHelp.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					try
					{
						ShowHelp();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			MenuGame = new JMenu();
			MenuControl = new JMenu();
			MenuView = new JMenu();
			MenuWindow = new JMenu();
			MenuHelp = new JMenu();

			MenuBar = new JMenuBar();

			if(osname.startsWith("Mac OS"))
			{
				MenuGame.setText(GetString("MenuGame"));
				MenuControl.setText(GetString("MenuControl"));
				MenuView.setText(GetString("MenuView"));
				MenuWindow.setText(GetString("MenuWindow"));
				MenuHelp.setText(GetString("MenuHelp"));

				MenuGame.add(MenuItemNew);
				MenuGame.add(MenuItemOpen);
				MenuGame.addSeparator();
				MenuGame.add(MenuItemClose);
				MenuGame.add(MenuItemSave);
				MenuGame.add(MenuItemSaveAs);
				MenuGame.add(MenuItemRevert);
				MenuGame.addSeparator();
				MenuGame.add(MenuItemCopyScreenShot);
				MenuGame.addSeparator();
				MenuGame.add(MenuItemAddTangram);
				MenuGame.add(MenuItemRemoveTangram);

				MenuControl.add(MenuItemZoomIn);
				MenuControl.add(MenuItemZoomOut);
				MenuControl.addSeparator();
				MenuControl.add(MenuItemRotateLeft);
				MenuControl.add(MenuItemRotateRight);
				MenuControl.addSeparator();
				MenuControl.add(MenuItemVerticalInvert);
				MenuControl.add(MenuItemHorizontalInvert);
				MenuControl.addSeparator();
				MenuControl.add(MenuItemChangeColor);
				MenuControl.addSeparator();
				MenuControl.add(MenuItemHide);

				MenuView.add(MenuItemShowHiddenTangram);

				MenuWindow.add(MenuItemMinimize);
				MenuWindow.add(MenuItemMaximize);

				MenuHelp.add(MenuItemHelp);
				MenuHelp.addSeparator();
				MenuHelp.add(MenuItemAbout);

				MenuBar.add(MenuGame);
				MenuBar.add(MenuControl);
				MenuBar.add(MenuView);
				MenuBar.add(MenuWindow);
				MenuBar.add(MenuHelp);
			}
			else
			{
				MenuGame.setText(GetString("MenuGame") + "(G)");
				MenuControl.setText(GetString("MenuControl") + "(C)");
				MenuView.setText(GetString("MenuView") + "(V)");
				MenuWindow.setText(GetString("MenuWindow") + "(W)");
				MenuHelp.setText(GetString("MenuHelp") + "(H)");

				MenuGame.setMnemonic(KeyEvent.VK_G);
				MenuControl.setMnemonic(KeyEvent.VK_C);
				MenuView.setMnemonic(KeyEvent.VK_V);
				MenuWindow.setMnemonic(KeyEvent.VK_W);
				MenuHelp.setMnemonic(KeyEvent.VK_H);

				MenuGame.add(MenuItemNew);
				MenuGame.add(MenuItemOpen);
				MenuGame.addSeparator();
				MenuGame.add(MenuItemSave);
				MenuGame.add(MenuItemSaveAs);
				MenuGame.add(MenuItemRevert);
				MenuGame.add(MenuItemClose);
				MenuGame.addSeparator();
				MenuGame.add(MenuItemCopyScreenShot);
				MenuGame.addSeparator();
				MenuGame.add(MenuItemAddTangram);
				MenuGame.add(MenuItemRemoveTangram);
				MenuGame.addSeparator();
				MenuGame.add(MenuItemQuit);

				MenuControl.add(MenuItemZoomIn);
				MenuControl.add(MenuItemZoomOut);
				MenuControl.addSeparator();
				MenuControl.add(MenuItemRotateLeft);
				MenuControl.add(MenuItemRotateRight);
				MenuControl.addSeparator();
				MenuControl.add(MenuItemVerticalInvert);
				MenuControl.add(MenuItemHorizontalInvert);
				MenuControl.addSeparator();
				MenuControl.add(MenuItemChangeColor);
				MenuControl.addSeparator();
				MenuControl.add(MenuItemHide);

				MenuView.add(MenuItemShowHiddenTangram);
				MenuWindow.add(MenuItemMaximize);
				MenuWindow.add(MenuItemMinimize);

				MenuHelp.add(MenuItemAbout);
				MenuHelp.addSeparator();
				MenuHelp.add(MenuItemHelp);

				MenuBar.add(MenuGame);
				MenuBar.add(MenuControl);
				MenuBar.add(MenuView);
				MenuBar.add(MenuWindow);
				MenuBar.add(MenuHelp);
			}

			FrameWindow.setJMenuBar(MenuBar);
			FrameWindow.addMouseListener(new MouseListener()
			{
				public void mouseClicked(MouseEvent e)
				{
				}

				public void mousePressed(MouseEvent e)
				{
					try
					{
						int i;
						boolean b = false;
						Point p = e.getPoint();
						String v = SelectedVar;
						int r = SelectedArray;

						for(i = 0; i < TangramLength; i ++)
						{
							while(true)
							{
								if(t1Selected(p.x, p.y, i))
								{
									if(t1[i].visible || ShowHiddenTangram)
									{
										b = SetSelected("t1", i);

										if("t1".equals(v))
											break;
									}
								}

								if(t2Selected(p.x, p.y, i))
								{
									if(t2[i].visible || ShowHiddenTangram)
									{
										b = SetSelected("t2", i);

										if("t2".equals(v))
											break;
									}
								}

								if(t3Selected(p.x, p.y, i))
								{
									if(t3[i].visible || ShowHiddenTangram)
									{
										b = SetSelected("t3", i);

										if("t3".equals(v))
											break;
									}
								}

								if(t4Selected(p.x, p.y, i))
								{
									if(t4[i].visible || ShowHiddenTangram)
									{
										b = SetSelected("t4", i);

										if("t4".equals(v))
											break;
									}
								}

								if(t5Selected(p.x, p.y, i))
								{
									if(t5[i].visible || ShowHiddenTangram)
									{
										b = SetSelected("t5", i);

										if("t5".equals(v))
											break;
									}
								}

								if(s1Selected(p.x, p.y, i))
								{
									if(s1[i].visible || ShowHiddenTangram)
									{
										b = SetSelected("s1", i);

										if("s1".equals(v))
											break;
									}
								}

								if(d1Selected(p.x, p.y, i))
								{
									if(d1[i].visible || ShowHiddenTangram)
									{
										b = SetSelected("d1", i);

										if("d1".equals(v))
											break;
									}
								}

								break;
							}
						}

						if(!b)
							CancelSelected();

						NowRefresh();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}

				public void mouseReleased(MouseEvent e)
				{
					try
					{
						NowRefresh();
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}

				public void mouseEntered(MouseEvent e)
				{
				}

				public void mouseExited(MouseEvent e)
				{
				}
			});
			FrameWindow.addMouseMotionListener(new MouseAdapter()
			{
				public void mouseDragged(MouseEvent e)
				{
					try
					{
						Point p = e.getPoint();
						ShapeValue SelectedOld;

						ProgressModifyied = true;
						ProgressRevertModifyied = true;

						if(SelectedTrue())
						{
							if(p.x < 0)
								p.x = 0;

							if(p.x > FrameWindow.getWidth())
								p.x = FrameWindow.getWidth();

							if(p.y < 50)
								p.y = 50;

							if(p.y > FrameWindow.getHeight())
								p.y = FrameWindow.getHeight();

							SelectedOld = new ShapeValue(SelectedTangram);

							SelectedTangram.setX(p.x);
							SelectedTangram.setY(p.y);

							NowRefresh(SelectedTangram, SelectedOld);
						}
					}
					catch(Exception e1)
					{
						ReturnException(e1, FrameWindow);
					}
				}
			});

			ResetGame();

			FrameWindow.setVisible(true);
		}
		catch(Exception e)
		{
			ReturnException(e, FrameWindow);
		}
	}

	public boolean t1Selected(int x, int y, int r) throws Exception
	{
		return GetShape.OnTriangle(x, y, t1[r].x, t1[r].y, t1[r].size, t1[r].rotate);
	}

	public boolean t2Selected(int x, int y, int r) throws Exception
	{
		return GetShape.OnTriangle(x, y, t2[r].x, t2[r].y, t2[r].size, t2[r].rotate);
	}

	public boolean t3Selected(int x, int y, int r) throws Exception
	{
		return GetShape.OnTriangle(x, y, t3[r].x, t3[r].y, t3[r].size, t3[r].rotate);
	}

	public boolean t4Selected(int x, int y, int r) throws Exception
	{
		return GetShape.OnTriangle(x, y, t4[r].x, t4[r].y, t4[r].size, t4[r].rotate);
	}

	public boolean t5Selected(int x, int y, int r) throws Exception
	{
		return GetShape.OnTriangle(x, y, t5[r].x, t5[r].y, t5[r].size, t5[r].rotate);
	}

	public boolean s1Selected(int x, int y, int r) throws Exception
	{
		return GetShape.OnSquare(x, y, s1[r].x, s1[r].y, s1[r].size, s1[r].rotate);
	}

	public boolean d1Selected(int x, int y, int r) throws Exception
	{
		return GetShape.OnDiamond(x, y, d1[r].x, d1[r].y, d1[r].size, d1[r].rotate);
	}

	public boolean CanAddTangram() throws Exception
	{
		return TangramLength != TangramMaximum;
	}

	public boolean CanRemoveTangram() throws Exception
	{
		return TangramLength != 1;
	}

	public boolean SelectedTrue() throws Exception
	{
		return SelectedTangram != null;
	}

	public boolean SelectedHidden() throws Exception
	{
		return !(SelectedTangram == null || SelectedTangram.visible);
	}

	public boolean SelectedCanZoomIn() throws Exception
	{
		return !(SelectedTangram == null || !(SelectedTangram.size + ZoomSize < ZoomMax));
	}

	public boolean SelectedCanZoomOut() throws Exception
	{
		return !(SelectedTangram == null || !(SelectedTangram.size - ZoomSize > 0));
	}

	public void NowRefresh() throws Exception
	{
		FrameWindow.repaint();
	}

	public void NowRefresh(ShapeValue sv, ShapeValue svo) throws Exception
	{
		FrameWindow.repaint((int)(sv.x - (sv.size * 1.5)) - 10, (int)(sv.y - (sv.size * 1.5)) - 10, (int)(sv.size * 3) + 20, (int)(sv.size * 3) + 20);
		FrameWindow.repaint((int)(svo.x - (svo.size * 1.5)) - 10, (int)(svo.y - (svo.size * 1.5)) - 10, (int)(sv.size * 3) + 20, (int)(sv.size * 3) + 20);
	}

	public void Refresh() throws Exception
	{
		boolean b;

		if(FrameWindow.getWidth() != OldWindowSize.width || FrameWindow.getHeight() != OldWindowSize.height)
		{
			ProgressModifyied = true;
			ProgressRevertModifyied = true;
		}
		OldWindowSize = FrameWindow.getSize();

		if(CurrentProgress == null)
		{
			b = false;
			if(ProgressModifyied)
				FrameWindow.setTitle(GetString("GameName") + " *");
			else
				FrameWindow.setTitle(GetString("GameName"));
			MenuItemSave.setText(GetString("MenuItemSave..."));
		}
		else
		{
			b = true;
			if(ProgressModifyied)
				FrameWindow.setTitle(GetString("GameName") + " - " + SimpleTool.BaseName(CurrentProgress) + " *");
			else
				FrameWindow.setTitle(GetString("GameName") + " - " + SimpleTool.BaseName(CurrentProgress));
			MenuItemSave.setText(GetString("MenuItemSave"));
		}
		MenuItemClose.setEnabled(b);
		if(CurrentProgress == null)
			b = false;
		else
			b = ProgressRevertModifyied;
		MenuItemRevert.setEnabled(b);
		MenuItemAddTangram.setEnabled(CanAddTangram());
		MenuItemRemoveTangram.setEnabled(CanRemoveTangram());

		MenuItemZoomIn.setEnabled(SelectedCanZoomIn());
		MenuItemZoomOut.setEnabled(SelectedCanZoomOut());
		MenuItemRotateLeft.setEnabled(SelectedTrue());
		MenuItemRotateRight.setEnabled(SelectedTrue());
		MenuItemVerticalInvert.setEnabled(SelectedTrue());
		MenuItemHorizontalInvert.setEnabled(SelectedTrue());
		MenuItemChangeColor.setEnabled(SelectedTrue());
		MenuItemHide.setEnabled(SelectedTrue());
		MenuItemHide.setState(SelectedHidden());
	}

	public boolean SetSelected(String Var, int Array) throws Exception
	{
		if(Var == null)
		{
			SelectedTangram = null;
			SelectedShape = null;
			SelectedVar = null;
			SelectedArray = 0;

			return true;
		}
		else
		{
			switch(Var)
			{
				case "t1":
				{
					SelectedTangram = t1[Array];
					SelectedShape = "Triangle";

					break;
				}
				case "t2":
				{
					SelectedTangram = t2[Array];
					SelectedShape = "Triangle";

					break;
				}
				case "t3":
				{
					SelectedTangram = t3[Array];
					SelectedShape = "Triangle";

					break;
				}
				case "t4":
				{
					SelectedTangram = t4[Array];
					SelectedShape = "Triangle";

					break;
				}
				case "t5":
				{
					SelectedTangram = t5[Array];
					SelectedShape = "Triangle";

					break;
				}
				case "s1":
				{
					SelectedTangram = s1[Array];
					SelectedShape = "Square";

					break;
				}
				case "d1":
				{
					SelectedTangram = d1[Array];
					SelectedShape = "Diamond";

					break;
				}
				default:
				{
					return false;
				}
			}

			SelectedVar = Var;
			SelectedArray = Array;

			return true;
		}
	}

	public void CancelSelected() throws Exception
	{
		SetSelected(null, 0);
	}

	public boolean AddTangram() throws Exception
	{
		if(CanAddTangram())
		{
			TangramLength ++;

			NowRefresh();

			return true;
		}

		return false;
	}

	public boolean RemoveTangram() throws Exception
	{
		if(CanRemoveTangram())
		{
			TangramLength --;

			if(SelectedArray == TangramLength)
				CancelSelected();

			NowRefresh();

			return true;
		}

		return false;
	}

	public void QuitGame() throws Exception
	{
		System.exit(0);
	}

	public void ZoomIn() throws Exception
	{
		if(SelectedCanZoomIn())
		{
			ProgressModifyied = true;
			ProgressRevertModifyied = true;

			if(SelectedTangram != null)
				SelectedTangram.setSize(SelectedTangram.size + ZoomSize);

			NowRefresh();
		}
	}

	public void ZoomOut() throws Exception
	{
		if(SelectedCanZoomOut())
		{
			ProgressModifyied = true;
			ProgressRevertModifyied = true;

			if(SelectedTangram != null)
				SelectedTangram.setSize(SelectedTangram.size - ZoomSize);

			NowRefresh();
		}
	}

	public void RotateLeft() throws Exception
	{
		ProgressModifyied = true;
		ProgressRevertModifyied = true;

		switch(SelectedShape)
		{
			case "Triangle":
				switch(SelectedTangram.rotate)
				{
					case 0:
						SelectedTangram.setRotate(7);
						break;
					case 1:
						SelectedTangram.setRotate(0);
						break;
					case 2:
						SelectedTangram.setRotate(1);
						break;
					case 3:
						SelectedTangram.setRotate(2);
						break;
					case 4:
						SelectedTangram.setRotate(3);
						break;
					case 5:
						SelectedTangram.setRotate(4);
						break;
					case 6:
						SelectedTangram.setRotate(5);
						break;
					case 7:
						SelectedTangram.setRotate(6);
						break;
				}
				break;
			case "Square":
				switch(SelectedTangram.rotate)
				{
					case 0:
						SelectedTangram.setRotate(1);
						break;
					case 1:
						SelectedTangram.setRotate(0);
						break;
				}
				break;
			case "Diamond":
				switch(SelectedTangram.rotate)
				{
					case 0:
						SelectedTangram.setRotate(3);
						break;
					case 1:
						SelectedTangram.setRotate(0);
						break;
					case 2:
						SelectedTangram.setRotate(1);
						break;
					case 3:
						SelectedTangram.setRotate(2);
						break;
					case 10:
						SelectedTangram.setRotate(11);
						break;
					case 11:
						SelectedTangram.setRotate(12);
						break;
					case 12:
						SelectedTangram.setRotate(13);
						break;
					case 13:
						SelectedTangram.setRotate(10);
						break;
				}
				break;
		}

		NowRefresh();
	}

	public void RotateRight() throws Exception
	{
		ProgressModifyied = true;
		ProgressRevertModifyied = true;

		switch(SelectedShape)
		{
			case "Triangle":
				switch(SelectedTangram.rotate)
				{
					case 0:
						SelectedTangram.setRotate(1);
						break;
					case 1:
						SelectedTangram.setRotate(2);
						break;
					case 2:
						SelectedTangram.setRotate(3);
						break;
					case 3:
						SelectedTangram.setRotate(4);
						break;
					case 4:
						SelectedTangram.setRotate(5);
						break;
					case 5:
						SelectedTangram.setRotate(6);
						break;
					case 6:
						SelectedTangram.setRotate(7);
						break;
					case 7:
						SelectedTangram.setRotate(0);
						break;
				}
				break;
			case "Square":
				switch(SelectedTangram.rotate)
				{
					case 0:
						SelectedTangram.setRotate(1);
						break;
					case 1:
						SelectedTangram.setRotate(0);
						break;
				}
				break;
			case "Diamond":
				switch(SelectedTangram.rotate)
				{
					case 0:
						SelectedTangram.setRotate(1);
						break;
					case 1:
						SelectedTangram.setRotate(2);
						break;
					case 2:
						SelectedTangram.setRotate(3);
						break;
					case 3:
						SelectedTangram.setRotate(0);
						break;
					case 10:
						SelectedTangram.setRotate(13);
						break;
					case 11:
						SelectedTangram.setRotate(10);
						break;
					case 12:
						SelectedTangram.setRotate(11);
						break;
					case 13:
						SelectedTangram.setRotate(12);
						break;
				}
				break;
		}

		NowRefresh();
	}

	public void VerticalInvert() throws Exception
	{
		ProgressModifyied = true;
		ProgressRevertModifyied = true;

		switch(SelectedShape)
		{
			case "Triangle":
				switch(SelectedTangram.rotate)
				{
					case 0:
						SelectedTangram.setRotate(4);
						break;
					case 1:
						SelectedTangram.setRotate(3);
						break;
					case 3:
						SelectedTangram.setRotate(1);
						break;
					case 4:
						SelectedTangram.setRotate(0);
						break;
					case 5:
						SelectedTangram.setRotate(7);
						break;
					case 7:
						SelectedTangram.setRotate(5);
						break;
				}
				break;
			case "Diamond":
				switch(SelectedTangram.rotate)
				{
					case 0:
						SelectedTangram.setRotate(10);
						break;
					case 1:
						SelectedTangram.setRotate(11);
						break;
					case 2:
						SelectedTangram.setRotate(12);
						break;
					case 3:
						SelectedTangram.setRotate(13);
						break;
					case 10:
						SelectedTangram.setRotate(0);
						break;
					case 11:
						SelectedTangram.setRotate(1);
						break;
					case 12:
						SelectedTangram.setRotate(2);
						break;
					case 13:
						SelectedTangram.setRotate(3);
						break;
				}
				break;
		}

		NowRefresh();
	}

	public void HorizontalInvert() throws Exception
	{
		ProgressModifyied = true;
		ProgressRevertModifyied = true;

		switch(SelectedShape)
		{
			case "Triangle":
				switch(SelectedTangram.rotate)
				{
					case 1:
						SelectedTangram.setRotate(7);
						break;
					case 2:
						SelectedTangram.setRotate(6);
						break;
					case 3:
						SelectedTangram.setRotate(5);
						break;
					case 5:
						SelectedTangram.setRotate(3);
						break;
					case 6:
						SelectedTangram.setRotate(2);
						break;
					case 7:
						SelectedTangram.setRotate(1);
						break;
				}
				break;
			case "Diamond":
				switch(SelectedTangram.rotate)
				{
					case 0:
						SelectedTangram.setRotate(10);
						break;
					case 1:
						SelectedTangram.setRotate(11);
						break;
					case 2:
						SelectedTangram.setRotate(12);
						break;
					case 3:
						SelectedTangram.setRotate(13);
						break;
					case 10:
						SelectedTangram.setRotate(0);
						break;
					case 11:
						SelectedTangram.setRotate(1);
						break;
					case 12:
						SelectedTangram.setRotate(2);
						break;
					case 13:
						SelectedTangram.setRotate(3);
						break;
				}
				break;
		}

		NowRefresh();
	}

	public void ChangeColor() throws Exception
	{
		Color Old;
		Color New;

		if(!MessageBoxShow)
		{
			MessageBoxShow = true;

			Old = SelectedTangram.color;

			ColorChooser = new JColorChooser();

			if(SelectedTangram != null)
			{
				New = ColorChooser.showDialog(FrameWindow, GetString("MenuItemChangeColor"), Old);

				if(New != null)
				{
					SelectedTangram.setColor(New);

					if(New != Old)
					{
						ProgressModifyied = true;
						ProgressRevertModifyied = true;

						NowRefresh();
					}
				}
			}

			MessageBoxShow = false;
		}
	}

	public void Hide() throws Exception
	{
		ProgressModifyied = true;
		ProgressRevertModifyied = true;

		if(SelectedTangram != null)
		{
			SelectedTangram.setVisible(!SelectedTangram.visible);

			if(!ShowHiddenTangram)
				CancelSelected();
		}

		NowRefresh();
	}

	public void ShowHiddenTangram() throws Exception
	{
		ShowHiddenTangram = !ShowHiddenTangram;

		if(!ShowHiddenTangram && !(SelectedTangram == null || SelectedTangram.visible))
			CancelSelected();

		NowRefresh();
	}

	public void ShowAbout() throws Exception
	{
		if(!MessageBoxShow)
		{
			MessageBoxShow = true;

			ShowMessage(FrameWindow, GetString("ApplicationVersion") + "\n" + GetString("ApplicationBy") + "\n\n" + GetString("ApplicationLasteModified") + "\n" + GetString("ApplicationCreationDate"), GetString("MenuItemAbout"), JOptionPane.INFORMATION_MESSAGE, "OK");

			MessageBoxShow = false;
		}
	}

	public void ShowHelp() throws Exception
	{
		if(!MessageBoxShow)
		{
			MessageBoxShow = true;

			ShowMessage(FrameWindow, GetString("HelpMessageText"), GetString("MenuItemHelp"), JOptionPane.INFORMATION_MESSAGE, "OK");

			MessageBoxShow = false;
		}
	}

	public void ReadProgress(String Path) throws Exception
	{
		int i;
		int n;
		int l;
		String P[];
		Object V[];
		File ThisFile = new File(Path);
		BufferedReader br = new BufferedReader(new FileReader(Path));
		String Data = br.readLine();

		OldProgressText = "";

		while(Data != null)
		{
			l = SimpleTool.StringCount(Data, ",") + 2;

			P = new String[l];
			V = new Object[l];

			OldProgressText += Data + "\n";

			if(Data.indexOf(":") == -1)
				P[0] = null;
			else
			{
				n = Data.indexOf(":") + 2;
				P[0] = Data.substring(0, Data.indexOf(":"));

				for(i = 1; ; i ++)
				{
					if(Data.indexOf(",", n) == -1)
					{
						P[i] = Data.substring(n, Data.length());
						break;
					}
					P[i] = Data.substring(n, Data.indexOf(",", n));
					n = Data.indexOf(",", n) + 2;
				}
			}

			for(i = 0; i < l && Data.indexOf(":") != -1; i ++)
				if(SimpleTool.IsNumber(P[i]))
					V[i] = SimpleTool.StringToInteger(P[i]);
				else
					if(P[i].equals("true") || P[i].equals("false"))
						V[i] = SimpleTool.StringToBoolean(P[i]);
					else
						if(P[i].indexOf(" ") != -1)
							V[i] = SimpleTool.StringToColor(P[i]);
						else
							V[i] = P[i];

			if(P[0] != null)
				switch(P[0])
				{
					case "MainWindow":
						FrameWindow.setBounds((screensize.width / 2) - ((int)V[1] / 2), (screensize.height / 2) - ((int)V[2] / 2), (int)V[1], (int)V[2]);
						break;
					case "Tangram":
					{
						CancelSelected();

						TangramLength = (int)V[1];

						break;
					}
					case "Triangle1":
						t1[(int)V[1]] = new ShapeValue((int)V[2], (int)V[3], (int)V[4], (int)V[5], (Color)V[6], (boolean)V[7]);
						break;
					case "Triangle2":
						t2[(int)V[1]] = new ShapeValue((int)V[2], (int)V[3], (int)V[4], (int)V[5], (Color)V[6], (boolean)V[7]);
						break;
					case "Triangle3":
						t3[(int)V[1]] = new ShapeValue((int)V[2], (int)V[3], (int)V[4], (int)V[5], (Color)V[6], (boolean)V[7]);
						break;
					case "Triangle4":
						t4[(int)V[1]] = new ShapeValue((int)V[2], (int)V[3], (int)V[4], (int)V[5], (Color)V[6], (boolean)V[7]);
						break;
					case "Triangle5":
						t5[(int)V[1]] = new ShapeValue((int)V[2], (int)V[3], (int)V[4], (int)V[5], (Color)V[6], (boolean)V[7]);
						break;
					case "Square1":
						s1[(int)V[1]] = new ShapeValue((int)V[2], (int)V[3], (int)V[4], (int)V[5], (Color)V[6], (boolean)V[7]);
						break;
					case "Diamond1":
						d1[(int)V[1]] = new ShapeValue((int)V[2], (int)V[3], (int)V[4], (int)V[5], (Color)V[6], (boolean)V[7]);
						break;
				}
			Data = br.readLine();
		}

		OldWindowSize = FrameWindow.getSize();

		ProgressModifyied = false;
		ProgressRevertModifyied = false;
		CurrentProgress = Path;

		NowRefresh();
	}

	public void WriteProgress(String Path) throws Exception
	{
		int i;
		String AllString;
		String Data;
		File ThisFile;
		BufferedWriter bw;
		ThisFile = new File(Path);

		AllString = "ColorTangram Progress\n\n";

		AllString += "Laste Modified in " + applicationname + " " + applicationversion + "\n\n\n";

		AllString += "MainWindow: " + FrameWindow.getWidth() + ", " + FrameWindow.getHeight() + "\n\n";
		AllString += "Tangram: " + TangramLength + "\n\n";

		for(i = 0; i < TangramMaximum; i ++)
		{
			AllString += "Triangle1: " + i + ", " + t1[i].x + ", " + t1[i].y + ", " + t1[i].size + ", " + t1[i].rotate + ", " + SimpleTool.ColorToString(t1[i].color) + ", " + t1[i].visible + "\n";
			AllString += "Triangle2: " + i + ", " + t2[i].x + ", " + t2[i].y + ", " + t2[i].size + ", " + t2[i].rotate + ", " + SimpleTool.ColorToString(t2[i].color) + ", " + t2[i].visible + "\n";
			AllString += "Triangle3: " + i + ", " + t3[i].x + ", " + t3[i].y + ", " + t3[i].size + ", " + t3[i].rotate + ", " + SimpleTool.ColorToString(t3[i].color) + ", " + t3[i].visible + "\n";
			AllString += "Triangle4: " + i + ", " + t4[i].x + ", " + t4[i].y + ", " + t4[i].size + ", " + t4[i].rotate + ", " + SimpleTool.ColorToString(t4[i].color) + ", " + t4[i].visible + "\n";
			AllString += "Triangle5: " + i + ", " + t5[i].x + ", " + t5[i].y + ", " + t5[i].size + ", " + t5[i].rotate + ", " + SimpleTool.ColorToString(t5[i].color) + ", " + t5[i].visible + "\n";
			AllString += "Square1: " + i + ", " + s1[i].x + ", " + s1[i].y + ", " + s1[i].size + ", " + s1[i].rotate + ", " + SimpleTool.ColorToString(s1[i].color) + ", " + s1[i].visible + "\n";
			AllString += "Diamond1: " + i + ", " + d1[i].x + ", " + d1[i].y + ", " + d1[i].size + ", " + d1[i].rotate + ", " + SimpleTool.ColorToString(d1[i].color) + ", " + d1[i].visible + "\n";
		}

		bw = new BufferedWriter(new FileWriter(ThisFile.getAbsoluteFile()));
		bw.write(AllString);
		bw.close();

		OldWindowSize = FrameWindow.getSize();

		ProgressModifyied = false;
		CurrentProgress = Path;

		NowRefresh();
	}

	public void NewProgress() throws Exception
	{
		File ThisFile;
		String FilePath;

		if(!MessageBoxShow)
		{
			MessageBoxShow = true;

			FileChooser = new FileDialog(FrameWindow, GetString("MenuItemNew"), FileDialog.SAVE);
			FileChooser.setFilenameFilter(new ColorTangramProgressFilter());

			FileChooser.setVisible(true);

			MessageBoxShow = false;

			if(FileChooser.getDirectory() != null)
			{
				ThisFile = new File(FileChooser.getDirectory() + "/" + FileChooser.getFile());
				FilePath = ThisFile.getPath();

				ResetGame();

				WriteProgress(FilePath);
				ReadProgress(FilePath);

				NowRefresh();
			}
		}
	}

	public void OpenProgress() throws Exception
	{
		File ThisFile;
		String FilePath;

		if(!MessageBoxShow)
		{
			MessageBoxShow = true;

			FileChooser = new FileDialog(FrameWindow, GetString("MenuItemOpen"), FileDialog.LOAD);
			FileChooser.setFilenameFilter(new ColorTangramProgressFilter());

			FileChooser.setVisible(true);

			MessageBoxShow = false;

			if(FileChooser.getDirectory() != null)
			{
				ThisFile = new File(FileChooser.getDirectory() + "/" + FileChooser.getFile());
				FilePath = ThisFile.getPath();

				if(ColorTangramProgressFilter.ColorTangramProgress(FilePath))
				{
					ProgressModifyied = false;
					ProgressRevertModifyied = false;

					ReadProgress(FilePath);

					NowRefresh();
				}
			}
		}
	}

	public void CloseProgress() throws Exception
	{
		CurrentProgress = null;

		ResetGame();

		OldWindowSize = FrameWindow.getSize();

		ProgressModifyied = false;
		ProgressRevertModifyied = false;

		NowRefresh();
	}

	public void SaveProgress() throws Exception
	{
		if(CurrentProgress == null)
			SaveAsProgress();
		else
			WriteProgress(CurrentProgress);
	}

	public void SaveAsProgress() throws Exception
	{
		File ThisFile;
		String FilePath;

		if(!MessageBoxShow)
		{
			MessageBoxShow = true;

			FileChooser = new FileDialog(FrameWindow, GetString("MenuItemSaveAs"), FileDialog.SAVE);
			FileChooser.setFilenameFilter(new ColorTangramProgressFilter());

			FileChooser.setVisible(true);

			MessageBoxShow = false;

			if(FileChooser.getDirectory() != null)
			{
				ThisFile = new File(FileChooser.getDirectory() + "/" + FileChooser.getFile());
				FilePath = ThisFile.getPath();

				WriteProgress(FilePath);

				ReadProgress(FilePath);

				NowRefresh();
			}
		}
	}

	public void RevertProgress() throws Exception
	{
		File ThisFile;
		BufferedWriter bw;

		if(!MessageBoxShow)
		{
			MessageBoxShow = true;

			if(ShowMessage(FrameWindow, GetString("RevertMessageText"), GetString("MenuItemRevert"), JOptionPane.QUESTION_MESSAGE, "OK", "Cancel") == 0)
			{
				ThisFile = new File(CurrentProgress);

				ProgressModifyied = false;
				ProgressRevertModifyied = false;

				bw = new BufferedWriter(new FileWriter(ThisFile.getAbsoluteFile()));
				bw.write(OldProgressText);
				bw.close();

				ReadProgress(CurrentProgress);

				WriteProgress(CurrentProgress);

				OldWindowSize = FrameWindow.getSize();

				NowRefresh();
			}

			MessageBoxShow = false;
		}
	}

	public void CopyScreenShot() throws Exception
	{
		BufferedImage ScreenShot = new Robot().createScreenCapture(new Rectangle(FrameWindow.getX(), FrameWindow.getY(), FrameWindow.getWidth(), FrameWindow.getHeight()));

		Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new ImageTransferable(ScreenShot), null);

		NowRefresh();
	}

	public void ResetGame() throws Exception
	{
		int i;
		int space;

		TangramLength = 0;
		AddTangram();

		CancelSelected();

		for(i = 0; i < TangramMaximum; i ++)
		{
			space = i * TangramSpace;

			t1[i] = new ShapeValue(240 + space, 160 + space, 200, 4, t1DefaultColor, true);
			t2[i] = new ShapeValue(140 + space, 260 + space, 200, 2, t2DefaultColor, true);
			t3[i] = new ShapeValue(290 + space, 260 + space, 100, 6, t3DefaultColor, true);
			t4[i] = new ShapeValue(140 + space, 410 + space, 100, 0, t4DefaultColor, true);
			t5[i] = new ShapeValue(373 + space, 393 + space, 134, 3, t5DefaultColor, true);
			s1[i] = new ShapeValue(240 + space, 360 + space, 100, 1, s1DefaultColor, true);
			d1[i] = new ShapeValue(390 + space, 210 + space, 100, 0, d1DefaultColor, true);
		}

		FrameWindow.setBounds(WindowX, WindowY, WindowWidth, WindowHeight);

		NowRefresh();
	}

	private String GetString(String ThisVariable, Object... ThisOther) throws Exception
	{
		return LanguageString(locallanguage, ClassName, ThisVariable, ThisOther);
	}
}
